/*******************************************************************
 * Filename:	BitOps.h
 * Description:	Defines a bitfield and creates the use table. 
 *				Also holds functions to manipulate metatable entries
 * 
 * Group 2:		nachOS
 * Author(s):	Jan Durakiewicz
 * 
 * Class:		CSE 325
 * Instructor:	David Duggan
 * Assignment:	Lab #5 Memory Manager
 * Assigned:	3/20/2013
 * Due:			4/2/2013
 *******************************************************************/
#ifndef BITOPS_H
#define BITOPS_H

short unsigned int power_of_two(short unsigned int exponent);

short unsigned int addressMask, allocMask, validMask;

short unsigned int get_page_alloc(unsigned short int* entry);
void set_page_alloc(unsigned short int* entry, short unsigned int isAlloc);

void init_masks();

/***
 * Checks whether a given page table entry is marked valid
 * @author Jan Durakiewicz
 * @param entry pointer to entry to be analyzed
 * @return 1 if the page is valid, 0 if not
 */
short unsigned int get_page_valid(unsigned short int* entry);

/***
 * Sets the validity for the given page table entry
 * @author Jan Durakiewicz
 * @param entry pointer to page table entry to set validity of
 * @param address whether to set as valid (1) or invalid (0)
 */
void set_page_valid(short unsigned int* entry, short unsigned int isValid);

/***
 * Extracts the physical page number from the given page table entry
 * @author Jan Durakiewicz
 * @param entry pointer to page table entry to extract from
 * @return numeric value of physucal page number
 */
short unsigned int get_page_address(short unsigned int* entry);

/***
 * Sets the physical page number for the given page table entry
 * @author Jan Durakiewicz
 * @param entry pointer to page table entry to set address of
 * @param address the physical page number to write to it
 */
void set_page_address(short unsigned int* entry, short unsigned int address);

void int_to_chars(unsigned int to_convert, unsigned char chars[3]);

#endif